package com.cangshi.service;


import com.cangshi.dao.GroupMapper;
import com.cangshi.entity.Group;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * Created by Eoly on 2017/1/16.
 */
@Service("groupService")
public class GroupServiceImpl implements GroupService {

    @Autowired
    GroupMapper groupMapper;


    public Integer addGroup(Group group) {
        return groupMapper.insertSelective(group);
    }

    public Integer getIdFromLastAdd() {
        return groupMapper.selectLastId();
    }

    public List<Group> findGroups(Integer line, Integer next, Integer goodsTypeId, String keyWord) {
        keyWord = keyWord != null ? "%" + keyWord + "%" : null;
        return groupMapper.selectByLimit(line, next, goodsTypeId, keyWord);
    }

    public List<Group> findGroupsByGroup(Group group, Integer line, Integer next) {
        return groupMapper.selectSimpleByGroup(group, line, next);
    }

    public Integer findCountByGroup(Group group, String keyWord) {
        keyWord = keyWord != null ? "%" + keyWord + "%" : null;
        return groupMapper.selectCountByGroup(group, keyWord);
    }

    public Group findGroupByGroupId(Integer groupId) {
        return groupMapper.selectByPrimaryKey(groupId);
    }

    public Integer updateGroup(Group group) {
        return groupMapper.updateByPrimaryKeySelective(group);
    }
}
